package com.example.springjpa.controller;

import com.example.springjpa.model.Student;
import com.example.springjpa.repository.StudentRepository;
import com.example.springjpa.vo.StudentResult;
import com.example.springjpa.vo.StudentVo;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/student")
public class StudentController {

    private StudentRepository studentRepository;

    public StudentController(StudentRepository studentRepository) {
        this.studentRepository = studentRepository;
    }

    @PostMapping
    public Student add(Student student) {
        return studentRepository.save(student);
    }

    @GetMapping
    public List<Student> list() {
        return studentRepository.findAll();
    }

    @GetMapping("/{clazzId}")
    public List<Map<String, Object>> queryByClazzId(@PathVariable("clazzId") Long clazzId) {
        return studentRepository.queryMap(clazzId);
    }

    @GetMapping("/vo/{clazzId}")
    public List<StudentVo> queryByClazzIdVo(@PathVariable("clazzId") Long clazzId) {
        return studentRepository.queryVo(clazzId);
    }

    @GetMapping("/interface/{clazzId}")
    public List<StudentResult> queryByClazzIdInterface(@PathVariable("clazzId") Long clazzId) {
        return studentRepository.queryInterface(clazzId);
    }
}
